# @ModuleName: customer_page
# @Author: zxl
# @Time: 2024/6/17 9:00'


from browseoperation import BrowserOperation
from userbrowser import UserBrowser


class CustomerPage:
    def __init__(self):
        # self.ub = UserBrowser()
        self.bo = BrowserOperation(UserBrowser.driver)

    def add_customer(self,customerNO = '', customerName = '', phone = '',
                     address = '', relationman = '', otherInfo = ''):
        self.bo.change_window('报价管理系统')
        self.bo.change_frame('Links')
        self.bo.click_element('xpath','//*[@id="Bar_panel0_b0"]/img')
        self.bo.change_frame('main')
        self.bo.click_element('xpath','/html/body/center/table[2]/tbody/tr[2]/td[2]/a')
        self.bo.change_window('新增客户信息')
        self.bo.input_text('name','customerNO',customerNO)
        self.bo.input_text('name', 'customerName', customerName)
        self.bo.input_text('name', 'phone', phone)
        self.bo.input_text('name', 'address', address)
        self.bo.input_text('name', 'relationman', relationman)
        self.bo.input_text('name', 'otherInfo', otherInfo)
        self.bo.click_element('name','saveButton')

    def get_add_suc_info(self):
        self.bo.change_window('添加记录成功')
        return self.bo.get_text('xpath','/html/body/center')

    def search_customer(self,customerNO = '', customerName = '', phone = '',
                     address = '', relationman = '', otherInfo = ''):
        self.bo.change_window('报价管理系统')
        self.bo.change_frame('Links')
        self.bo.click_element('xpath','//*[@id="Bar_panel0_b1"]/img')
        self.bo.change_frame('main')
        self.bo.input_text('name','customerNO',customerNO)
        self.bo.input_text('name', 'customerName', customerName)
        self.bo.input_text('name', 'phone', phone)
        self.bo.input_text('name', 'address', address)
        self.bo.input_text('name', 'relationman', relationman)
        self.bo.input_text('name', 'otherInfo', otherInfo)
        self.bo.click_element('name','saveButton')
        # self.bo.change_window()


    def modify_customer(self,customerNO = '', customerName = '', phone = '',
                     address = '', relationman = '', otherInfo = ''):
        # self.bo.change_window('报价管理系统')
        # self.bo.change_frame('Links')
        # self.bo.click_element('xpath', '//*[@id="Bar_panel0_b0"]/img')
        # self.bo.change_frame('main')
        self.search_customer(customerNO)
        self.bo.click_element('xpath','/html/body/center/form/table[1]/tbody/tr[2]/td[7]/a[2]')
        self.bo.change_window('更新客户信息')
        # self.bo.input_text('name', 'customerNo', customerNO)
        self.bo.input_text('name', 'customerName', customerName)
        self.bo.input_text('name', 'phone', phone)
        self.bo.input_text('name', 'address', address)
        self.bo.input_text('name', 'relationman', relationman)
        self.bo.input_text('name', 'otherInfo', otherInfo)
        self.bo.click_element('name', 'saveButton')

    def get_modify_suc_info(self):
        self.bo.change_window('更新记录成功')
        return self.bo.get_text('xpath','/html/body/center')



